package com.sdp.khy.baotou.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sdp.core.bizc.vo.Result;
import com.sdp.khy.baotou.db.khy_protect_price_pact.entity.KhyProtectPricePact;
import com.sdp.khy.baotou.db.khy_protect_price_pact.service.IKhyProtectPricePactService;
import com.sdp.khy.baotou.db.khy_transport_pact.entity.KhyTransportPact;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2023-12-03
 */
@RestController
@RequestMapping("/KhyProtectPricePactController")
public class KhyProtectPricePactController {

	@Autowired
	private IKhyProtectPricePactService iKhyProtectPricePactService;

	@GetMapping(value = "/queryProtectPricePact")
	public Result<?> queryProtectPricePact() {
		LambdaQueryWrapper<KhyProtectPricePact> queryWrapper = new LambdaQueryWrapper<>();
		KhyProtectPricePact pact = iKhyProtectPricePactService.getOne(queryWrapper, false);
		return Result.ok(pact==null?new KhyTransportPact():pact);
	}
	
	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody KhyProtectPricePact pact) {
		if(pact==null) {
			return Result.error("信息为空");
		}
		if(StringUtils.isEmpty(pact.getKeyId())) {
			iKhyProtectPricePactService.save(pact);
		}else {
			iKhyProtectPricePactService.updateById(pact);
		}
		return Result.ok(pact);
	}
}

